<script setup>
import { ref } from 'vue'
import ToolCard from '@/components/ToolCard.vue'

const toolCategories = ref([
  {
    id: 1,
    name: '基础修复工具',
    description: '用于日常修复工作的基础工具',
    tools: [
      {
        id: 1,
        name: '修复笔刷',
        level: 3,
        unlocked: true,
        image: 'https://img.freepik.com/free-photo/paint-brushes-dark-wooden-background_93675-129057.jpg',
        description: '用于修复纸张表面的轻微损伤',
        usage: '轻轻涂抹受损区域',
        experience: 1500
      },
      {
        id: 2,
        name: '补纸工具',
        level: 2,
        unlocked: true,
        image: 'https://img.freepik.com/free-photo/flat-lay-natural-paper-arrangement_23-2149080862.jpg',
        description: '用于修补破损的纸张',
        usage: '精确裁剪，对齐纹理',
        experience: 1200
      }
    ]
  },
  {
    id: 2,
    name: '专业修复设备',
    description: '适用于复杂修复工作的专业设备',
    tools: [
      {
        id: 3,
        name: '数字扫描仪',
        level: 5,
        unlocked: false,
        image: 'https://img.freepik.com/free-photo/scanner-white_1232-2816.jpg',
        description: '高精度扫描古籍文字',
        usage: '需要专业培训',
        requiredExp: 3000
      },
      {
        id: 4,
        name: '温湿度调节器',
        level: 4,
        unlocked: false,
        image: 'https://img.freepik.com/free-photo/air-humidifier-table_93675-130045.jpg',
        description: '控制修复环境的温湿度',
        usage: '根据古籍材质调节参数',
        requiredExp: 2500
      }
    ]
  }
])

const selectedTool = ref(null)

const showToolDetail = (tool) => {
  selectedTool.value = tool
}
</script>

<template>
  <div class="tools-container">
    <div class="tools-header">
      <h1>修复工具库</h1>
      <div class="tools-filters">
        <button class="filter-btn active">全部工具</button>
        <button class="filter-btn">已解锁</button>
        <button class="filter-btn">待解锁</button>
      </div>
    </div>

    <div class="categories-grid">
      <div v-for="category in toolCategories" :key="category.id" class="category-section">
        <div class="category-header">
          <h2>{{ category.name }}</h2>
          <p class="category-desc">{{ category.description }}</p>
        </div>

        <div class="tools-grid">
          <ToolCard 
            v-for="tool in category.tools"
            :key="tool.id"
            :tool="tool"
            @click="showToolDetail(tool)"
          />
        </div>
      </div>
    </div>

    <!-- 工具详情弹窗 -->
    <div v-if="selectedTool" class="tool-detail-modal" @click="selectedTool = null">
      <div class="modal-content" @click.stop>
        <button class="close-btn" @click="selectedTool = null">×</button>
        <div class="tool-detail-content">
          <div class="tool-image">
            <img :src="selectedTool.image" :alt="selectedTool.name">
          </div>
          <div class="tool-info">
            <h3>{{ selectedTool.name }}</h3>
            <div class="tool-meta">
              <span class="tool-level">等级 {{ selectedTool.level }}</span>
              <span :class="['tool-status', selectedTool.unlocked ? 'unlocked' : 'locked']">
                {{ selectedTool.unlocked ? '已解锁' : '未解锁' }}
              </span>
            </div>
            <div class="tool-description">
              <h4>工具说明</h4>
              <p>{{ selectedTool.description }}</p>
            </div>
            <div class="tool-usage">
              <h4>使用方法</h4>
              <p>{{ selectedTool.usage }}</p>
            </div>
            <div v-if="!selectedTool.unlocked" class="unlock-info">
              <h4>解锁条件</h4>
              <p>需要修复经验: {{ selectedTool.requiredExp }}</p>
              <button class="unlock-btn" disabled>
                经验值不足
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.tools-container {
  min-height: calc(100vh - 72px);
  padding: 0 40px;
  max-width: 1800px;
  margin: 0 auto;
}

.tools-header {
  background: white;
  border-radius: 16px;
  padding: 32px;
  margin-bottom: 40px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.tools-header h1 {
  font-size: 28px;
  color: #4a4a4a;
  margin-bottom: 24px;
}

.tools-filters {
  display: flex;
  gap: 16px;
}

.filter-btn {
  padding: 8px 20px;
  border: none;
  background: #f5f5f5;
  border-radius: 20px;
  color: #666;
  cursor: pointer;
  transition: all 0.3s;
}

.filter-btn:hover,
.filter-btn.active {
  background: #8b4513;
  color: white;
}

.categories-grid {
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.category-section {
  background: white;
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.category-header {
  margin-bottom: 24px;
}

.category-header h2 {
  font-size: 24px;
  color: #4a4a4a;
  margin-bottom: 8px;
}

.category-desc {
  color: #666;
  font-size: 16px;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}

.tool-detail-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  border-radius: 16px;
  width: 90%;
  max-width: 1000px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  padding: 32px;
}

.close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
}

.tool-detail-content {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 32px;
}

.tool-image {
  border-radius: 12px;
  overflow: hidden;
}

.tool-image img {
  width: 100%;
  height: 300px;
  object-fit: cover;
}

.tool-info h3 {
  font-size: 24px;
  color: #4a4a4a;
  margin-bottom: 16px;
}

.tool-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.tool-level {
  padding: 4px 12px;
  background: #f0f0f0;
  border-radius: 12px;
  color: #666;
}

.tool-status {
  padding: 4px 12px;
  border-radius: 12px;
}

.tool-status.unlocked {
  background: #e8f5e9;
  color: #42b983;
}

.tool-status.locked {
  background: #ffebee;
  color: #ef5350;
}

.tool-description,
.tool-usage,
.unlock-info {
  margin-bottom: 24px;
}

.tool-info h4 {
  font-size: 18px;
  color: #4a4a4a;
  margin-bottom: 8px;
}

.tool-info p {
  color: #666;
  line-height: 1.6;
}

.unlock-btn {
  margin-top: 16px;
  padding: 12px 24px;
  background: #f0f0f0;
  border: none;
  border-radius: 8px;
  color: #999;
  cursor: not-allowed;
}

@media (max-width: 1200px) {
  .tool-detail-content {
    grid-template-columns: 1fr;
  }
}
</style> 